// pages/home/course/course.js
const app = getApp()
var base_url = app.globalData.url
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.getStorage({
      key: 'shizi_lst',
      success: function (res) {
          that.setData({
            shizi_lst : res['data']
          })
      },
    }) 
    wx.getStorage({
      key: 'kewen_lst',
      success: function (res) {
        that.setData({
          kewen_lst: res['data']
        })
      },
    }) 
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  gotoWords:function(e){
    wx.removeStorage({
      key: 'wordDatas',
      success: function(res) {},
    })
    var get_courseName = e.currentTarget.dataset.name
    console.log(get_courseName)
    wx.request({
      url: base_url+'/getWordDatas/',
      method: 'POST',
      data: {
        get_courseName: get_courseName,
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        console.log(res.data['words_lst'])
        if (res.data['flag'] == true) {
          wx.setStorage({
            key: 'wordDatas',
            data: res.data['words_lst'],
            success: function (res) {
              wx.navigateTo({
                url: '../word/word',
                success: function (res) {
                  console.log(res)
                },
                fail: function () {
                }
              })
            }
          })
          
        } else {

        }
      }
    })
    
  }
})